/* Copyright 2014 Nate Eisner, Noah Bahr
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.uwp.kcwm;

import java.io.FileNotFoundException;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.ImageView;

public class Artifact extends Activity {
	ImageView imgV;
	WebView wView;
	String exhibitNum, artifactNum;

	// URL for webserver
	private static final String SITEURL = "http://gracefullyengineered.com/kcwm/";

	/** Called when the activity is first created. 
	 *  Loads picture and information for artifact
	 * */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			exhibitNum = extras.getString("exhibitNum");
			artifactNum = extras.getString("artifactNum");
		}
		
		setContentView(R.layout.artifact);
		getActionBar().setTitle(
				"Exhibit " + exhibitNum + " - Artifact " + artifactNum);
		imgV = (ImageView) findViewById(R.id.artifactImage);
		Bitmap bitmap = null;
		try {
			bitmap = BitmapFactory.decodeStream(this
			        .openFileInput("artifact"));
			imgV.setImageBitmap(bitmap);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		wView = (WebView) findViewById(R.id.artifactText);
		wView.loadUrl(SITEURL + exhibitNum + "/artifacts/" + artifactNum
				+ ".html");

	}

	@Override
	public void onResume() {
		super.onResume();
		wView.loadUrl(SITEURL + exhibitNum + "/artifacts/" + artifactNum
				+ ".html");
	}
}
